#!/bin/bash

function assert_ok()
{
    if [ "$1" != 0 ]; then
        exit 1
    fi
}

function command_exists () {
    type "$1" &> /dev/null ;
}

rm -rf storage/*/

mkdir storage
mkdir storage/app
mkdir storage/debugbar
mkdir storage/framework
mkdir storage/logs
mkdir storage/framework/sessions
mkdir storage/framework/cache
mkdir storage/framework/views

chmod -R 766 storage || assert_ok $?
chmod 766 bootstrap/cache || assert_ok $?

# 更改用户组
chown www:www storage

composer install -o --no-dev || assert_ok $?

php artisan env || assert_ok $?
php artisan route:cache || assert_ok $?
php artisan route:list > /dev/null 2>&1 || assert_ok $?
php artisan view:clear || assert_ok $?
php artisan storage:link

php80 artisan cache:clear
php80 artisan config:clear
npm run dev

php80 artisan route:clear
php80 artisan config:clear
php80 artisan cache:clear

php artisan route:clear
php artisan config:clear
php artisan cache:clear

php74 artisan route:clear
php74 artisan config:clear
php74 artisan cache:clear

npm run prod || assert_ok $?

exit 0